﻿using AiXiu.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace AiXiu.Web.Ashx
{
    /// <summary>
    /// CaptchaHandler 的摘要说明
    /// </summary>
    public class CaptchaHandler : IHttpHandler,IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            //获取一个随机码的图片

            CaptchaGenerator captchaGenerator = new CaptchaGenerator(6);
            string code = captchaGenerator.Text;
            Bitmap bitmap = captchaGenerator.Image;

            context.Session.Add("yzm", code);

            bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg);
            context.Response.ContentType = "imags/ipeg";
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}